﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;

namespace RefOffPDA
{
    /*
     * Class: Goal
     * 
     * Use: Form used to record a Goal scored during a match, displaying a list
     *      of players on the pitch at that time in the form of buttons
     *      
     * Author: Mike Skaife, mcs3@aber.ac.uk
     */ 
    public partial class Goal : Form
    {
        //Details required to connect to the database
        string conString;
        SqlCeConnection conn;

        //The current Match object
        Match theMatch;

        //Indicates whether the home or
        //away team scored the goal
        String homeOrAway;

        //id of the current Match in the database
        int matchId;

        //Used to indicate which player has been identified
        //as having scored the Goal
        Button clickedButton;
        int player_id;

        //Indicates whether the Goal was an own goal
        public bool ownGoal = false;

        //Indicates whether the Goal was a golden goal
        //during a period of extra time
        public bool isGoldenGoal = false;
        
        public Goal(Match match, String homeAway)
        {
            InitializeComponent();
            theMatch = match;
            homeOrAway = homeAway;
        }

        //This method is used to record the goal within the database
        private void scoreGoal(Button pressed)
        {
            //Used later to indicate whether this is an own goal
            int isOwnGoal = 0;

            //Indicate which button on the Goal screen was pressed
            //and obtain id of goalscorer from this
            clickedButton = pressed;
            player_id = Int32.Parse(clickedButton.Tag.ToString());

            //The id of the current match
            matchId = theMatch.match_id;

            //The current value of the Match timer
            String timeOfIncident = theMatch.tenMinutes + theMatch.minutes + ":" + theMatch.tenSeconds + theMatch.seconds;
            
            //Set value of variable to indicate whether this was an own goal
            if (ownGoal)
            {
                isOwnGoal = 1;
            }

            //Create and execute SQL command to record the Goal in the database
            connectToDatabase();
            string command = @"INSERT INTO goal(player_id,match_id,time,own_goal) VALUES(@id,@match,@time,@owngoal);";
            using (SqlCeCommand insert_goal = new SqlCeCommand(command, conn))
            {
                insert_goal.Parameters.AddWithValue("@id", player_id);
                insert_goal.Parameters.AddWithValue("@match", matchId);
                insert_goal.Parameters.AddWithValue("@time", timeOfIncident);
                insert_goal.Parameters.AddWithValue("@owngoal", isOwnGoal);
                insert_goal.ExecuteNonQuery();
            }

            //If the Goal is a golden goal during extra time, this code is run
            if (isGoldenGoal)
            {
                //Confirm that user wants to end the match now the golden goal has been scored
                if ((MessageBox.Show("Golden goal scored - end match?", "Golden Goal", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) == DialogResult.Yes)
                {
                    //Hide this screen and the main Match screen
                    this.Visible = false;
                    theMatch.Visible = false;

                    //Close the port connected to the GPS antenna
                    theMatch.gpsReader.closePort();
                }
            }

            //Disconnect from the database
            closeDatabaseConnection();            
        }

        //This method is used to create a connection to the database
        private void connectToDatabase()
        {            
            // Retrieve the connection string
            conString = @"Data Source=\Program Files\RefOffPDA\RefOffPDA_DB.sdf";

            // Open the connection using the connection string
            conn = new SqlCeConnection(conString);
            conn.Open();           
        }

        //This method disconnects from the database
        private void closeDatabaseConnection()
        {
            //Close the database connection
            conn.Close();
        }

        //This method is run if the first player in the list scored the Goal
        private void GoalPlayer1Btn_Click(object sender, EventArgs e)
        {
            //Record the Goal in the database
            scoreGoal(GoalPlayer1Btn);

            //Variable to hold current score in Match for this team
            int score;

            //This code is run if the home team scored the Goal
            if (homeOrAway.Equals("home"))
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
            }
            //This code runs if the away team scored the Goal
            else
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
            }

            //Hide this screen to display the main Match screen
            this.Visible = false;

            //Reset value of own goal variable for use next time
            ownGoal = false;
        }

        //This method is run if the second player in the list scored the Goal
        private void GoalPlayer2Btn_Click(object sender, EventArgs e)
        {
            //Record the Goal in the database
            scoreGoal(GoalPlayer2Btn);

            //Variable to hold current score in Match for this team
            int score;

            //This code is run if the home team scored the Goal
            if (homeOrAway.Equals("home"))
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
            }
            //This code runs if the away team scored the Goal
            else
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
            }

            //Hide this screen to display the main Match screen
            this.Visible = false;

            //Reset value of own goal variable for use next time
            ownGoal = false;
        }

        //This method is run if the third player in the list scored the Goal
        private void GoalPlayer3Btn_Click(object sender, EventArgs e)
        {
            //Record the Goal in the database
            scoreGoal(GoalPlayer3Btn);

            //Variable to hold current score in Match for this team
            int score;

            //This code is run if the home team scored the Goal
            if (homeOrAway.Equals("home"))
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
            }
            //This code runs if the away team scored the Goal
            else
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
            }

            //Hide this screen to display the main Match screen
            this.Visible = false;

            //Reset value of own goal variable for use next time
            ownGoal = false;
        }

        //This method is run if the fourth player in the list scored the Goal
        private void GoalPlayer4Btn_Click(object sender, EventArgs e)
        {
            //Record the Goal in the database
            scoreGoal(GoalPlayer4Btn);

            //Variable to hold current score in Match for this team
            int score;

            //This code is run if the home team scored the Goal
            if (homeOrAway.Equals("home"))
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
            }
            //This code runs if the away team scored the Goal
            else
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
            }

            //Hide this screen to display the main Match screen
            this.Visible = false;

            //Reset value of own goal variable for use next time
            ownGoal = false;
        }

        //This method is run if the fifth player in the list scored the Goal
        private void GoalPlayer5Btn_Click(object sender, EventArgs e)
        {
            //Record the Goal in the database
            scoreGoal(GoalPlayer5Btn);

            //Variable to hold current score in Match for this team
            int score;

            //This code is run if the home team scored the Goal
            if (homeOrAway.Equals("home"))
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
            }
            //This code runs if the away team scored the Goal
            else
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
            }

            //Hide this screen to display the main Match screen
            this.Visible = false;

            //Reset value of own goal variable for use next time
            ownGoal = false;
        }

        //This method is run if the sixth player in the list scored the Goal
        private void GoalPlayer6Btn_Click(object sender, EventArgs e)
        {
            //Record the Goal in the database
            scoreGoal(GoalPlayer6Btn);

            //Variable to hold current score in Match for this team
            int score;

            //This code is run if the home team scored the Goal
            if (homeOrAway.Equals("home"))
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
            }
            //This code runs if the away team scored the Goal
            else
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
            }

            //Hide this screen to display the main Match screen
            this.Visible = false;

            //Reset value of own goal variable for use next time
            ownGoal = false;
        }

        //This method is run if the seventh player in the list scored the Goal
        private void GoalPlayer7Btn_Click(object sender, EventArgs e)
        {
            //Record the Goal in the database
            scoreGoal(GoalPlayer7Btn);

            //Variable to hold current score in Match for this team
            int score;

            //This code is run if the home team scored the Goal
            if (homeOrAway.Equals("home"))
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
            }
            //This code runs if the away team scored the Goal
            else
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
            }

            //Hide this screen to display the main Match screen
            this.Visible = false;

            //Reset value of own goal variable for use next time
            ownGoal = false;
        }

        //This method is run if the eighth player in the list scored the Goal
        private void GoalPlayer8Btn_Click(object sender, EventArgs e)
        {
            //Record the Goal in the database
            scoreGoal(GoalPlayer8Btn);

            //Variable to hold current score in Match for this team
            int score;

            //This code is run if the home team scored the Goal
            if (homeOrAway.Equals("home"))
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
            }
            //This code runs if the away team scored the Goal
            else
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
            }

            //Hide this screen to display the main Match screen
            this.Visible = false;

            //Reset value of own goal variable for use next time
            ownGoal = false;
        }

        //This method is run if the ninth player in the list scored the Goal
        private void GoalPlayer9Btn_Click(object sender, EventArgs e)
        {
            //Record the Goal in the database
            scoreGoal(GoalPlayer9Btn);

            //Variable to hold current score in Match for this team
            int score;

            //This code is run if the home team scored the Goal
            if (homeOrAway.Equals("home"))
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
            }
            //This code runs if the away team scored the Goal
            else
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
            }

            //Hide this screen to display the main Match screen
            this.Visible = false;

            //Reset value of own goal variable for use next time
            ownGoal = false;
        }

        //This method is run if the tenth player in the list scored the Goal
        private void GoalPlayer10Btn_Click(object sender, EventArgs e)
        {
            //Record the Goal in the database
            scoreGoal(GoalPlayer10Btn);

            //Variable to hold current score in Match for this team
            int score;

            //This code is run if the home team scored the Goal
            if (homeOrAway.Equals("home"))
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
            }
            //This code runs if the away team scored the Goal
            else
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
            }

            //Hide this screen to display the main Match screen
            this.Visible = false;

            //Reset value of own goal variable for use next time
            ownGoal = false;
        }

        //This method is run if the eleventh player in the list scored the Goal
        private void GoalPlayer11Btn_Click(object sender, EventArgs e)
        {
            //Record the Goal in the database
            scoreGoal(GoalPlayer11Btn);

            //Variable to hold current score in Match for this team
            int score;

            //This code is run if the home team scored the Goal
            if (homeOrAway.Equals("home"))
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
            }
            //This code runs if the away team scored the Goal
            else
            {
                //Determine if the Goal is an own goal
                if (ownGoal)
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchHomeScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchHomeScoreLLbl.Text = score.ToString();
                }
                //If Goal was not an own goal...
                else
                {
                    //Obtain current score for the team before Goal was scored
                    score = Int32.Parse(theMatch.MatchAwayScoreLLbl.Text);
                    //Increase score after Goal
                    score++;
                    //Indicate new score on Match screen
                    theMatch.MatchAwayScoreLLbl.Text = score.ToString();
                }
            }

            //Hide this screen to display the main Match screen
            this.Visible = false;

            //Reset value of own goal variable for use next time
            ownGoal = false;
        }

        //This method is run when the 'Cancel' button is pressed
        private void CancelButton_Click(object sender, EventArgs e)
        {
            //Hide this screen to display the main Match screen
            this.Visible = false;

            //Reset the own goal variable for use next time
            ownGoal = false;
        }

        //This method is run if the 'Own Goal' button is clicked,
        //to display all the players from the opposing team so the
        //scorer of the own goal can be indicated
        private void ownGoalBtn_Click(object sender, EventArgs e)
        {
            //This code runs if the Goal is being awarded to the home team
            if(homeOrAway.Equals("home"))
            {
                //Set own goal variable in away team screen
                theMatch.awayGoal.ownGoal = true;
                //Display players from away team
                theMatch.awayGoal.Visible = true;
                //Hide this screen
                this.Visible = false;
            }
            //This code runs if the Goal is being awarded to the away team
            else
            {
                //Set own goal variable in home team screen
                theMatch.homeGoal.ownGoal = true;
                //Display players from home team
                theMatch.homeGoal.Visible = true;
                //Hide this screen
                this.Visible = false;
            }
        }
    }
}